package com.vcredit.creditcat.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.RecommendCard;
import com.vcredit.creditcat.persistence.base.RecommendCardMapper;

/**
 * 
 **/
@Service
public class RecommendCardService {
	@Autowired
	private RecommendCardMapper mapper;

	public void insert(RecommendCard obj) {
		mapper.insert(obj);
	}

	public void update(RecommendCard obj) {
		mapper.update(obj);
	}
	
	private List<RecommendCard> findAll() {
		return mapper.findAll();
	}
	
	public Map<Long,RecommendCard> findAllForMap() {
		Map<Long, RecommendCard> result = new HashMap<Long, RecommendCard>();
		List<RecommendCard> list = this.findAll();
		for (RecommendCard obj : list) {
			result.put(obj.getCardId(), obj);
		}
		return result;
	}

	public List<RecommendCard> find(RecommendCard obj) {
		return mapper.find(obj);
	}

	public List<RecommendCard> findByType(int type) {
		List<RecommendCard> cards = this.findAll();
		List<RecommendCard> newCards = new ArrayList<RecommendCard>();
		for (RecommendCard card : cards) {
			if (card.getType() == type) {
				newCards.add(card);
			}
		}
		return newCards;
	}

	public List<RecommendCard> queryAll() {
		return findAll();
	}
	
	public RecommendCard findById(long cardId){
		return mapper.findById(cardId);
	}

}